<?php
if(!defined('IN_SONG')) exit('No direct script access allowed');  
/**
 * Class module
 * 
 * @package         Kernel
 * @subpackage      Database
 * @version         0.1
 * @copyright       Song (c) 2011
 */  
if(!class_exists('DBMySqli')){
    require_once LIB .DS. 'database.mysqli.php';
} 

abstract class Database extends DBMySQLi  
{      
    const TYPE_MYSQL = 1;
    const TYPE_MYSQLI = 2;
    const TYPE_PDO = 3; 
           
    /**
     * Gets a reference to the Database object instance
     *
     * @return object                             
     * @access public
     */
    function getInstance() {
        static $instance; 
        if (!$instance) {
            $instance = new self();
        }
        return $instance;
    }
    
    function __construct(){
        if (IS_DEBUG){
            Debug::getInstance()->mark('Connection to Database', 'system.database.' . get_class($this)); 
        }
            
        $arrConfig = parse_ini_file(ROOT .DS. 'config' .DS. 'database.ini', true);    
        parent::__construct($arrConfig); 
        
    }
    
    /**
     * Get Log query
     *
     * @return Array
     */
    public function getLog() {
        return $this->_log;
    }
    
    /**
     * Get Database Object
     *
     * @return Array
     */
    public static function getDBO() {
        return self::$instances; 
    }
    
    /**
     * Get Microtime
     *
     * @return float
     */
    public function getMicrotime() {
        list($usec, $sec) = explode(' ', microtime());
        return ((float)$usec + (float)$sec);
    }
}
?>
